/*
 * @description  : 文书接口
 * @descriptionDetail: 文书接口
 * @copyright    : 浙江烟草
 * @author       : qyx
 * @create       : 2022-09-27 09:58:57
 */

import apiUrl from "@/common/api_urls/internal";
import reqHelper from "@/common/reqHelper";
let baseUrl = process.uniEnv.BASE_API;

export default {
  /**
       * 业务审批列表分页查询
         * @param {*} page 
         * @param {*} limit 
         * @param {*} paras
         * @returns 
     */
  selectApprovalList(page, limit, paras) {
    return reqHelper.postJson({ page: page, limit: limit, paras: paras, }, apiUrl.internal.selectApprovalList);
  },
  selectApprovalDetail(docInsUuid, menuCode) {
    return reqHelper.postForm({ docInsUuid: docInsUuid, menuCode: menuCode, }, apiUrl.internal.selectApprovalDetail);
  },
  selectApprovalTimeLine(docInsUuid, menuCode) {
    return reqHelper.postForm({ docInsUuid: docInsUuid, menuCode: menuCode, }, apiUrl.internal.selectApprovalTimeLine);
  },
  selectApprovalContent(id, bizUuid, docInsUuid, menuCode) {
    return reqHelper.postForm({ id: id, bizUuid: bizUuid, docInsUuid: docInsUuid, menuCode: menuCode, }, apiUrl.internal.selectApprovalcontent);
  },
  selectNoticeDetail(id, bizUuid, docInsUuid, menuCode) {
    return reqHelper.postForm({ id: id, bizUuid: bizUuid, docInsUuid: docInsUuid, menuCode: menuCode, }, apiUrl.internal.selectNoticeDetail);
  },
  selectCollaDetail(id, bizUuid, docInsUuid, menuCode) {
    return reqHelper.postForm({ id: id, bizUuid: bizUuid, docInsUuid: docInsUuid, menuCode: menuCode, }, apiUrl.internal.selectCollaDetail);
  },
  selectTaskDetail(id, bizUuid, docInsUuid, menuCode) {
    return reqHelper.postForm({ id: id, bizUuid: bizUuid, docInsUuid: docInsUuid, menuCode: menuCode, }, apiUrl.internal.selectTaskDetail);
  },
  selectprocess(docUuid, id, menuCode) {
    return reqHelper.postForm({ docUuid: docUuid, id: id, menuCode: menuCode, }, apiUrl.internal.selectprocess);
  },
  selectprocessParson(page, limit, gfCode, stepCode,bizId, isReport, menuCode) {
    return reqHelper.postForm({ page: page, limit: limit, gfCode, stepCode,bizId, isReport: isReport, menuCode: menuCode, }, apiUrl.internal.selectprocessParson);
  },
  selectprocessAgree(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.selectprocessAgree + ps);
  },
  selectprocessInitOverrule(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&stepCode=${paras.stepCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.selectprocessInitOverrule + ps);
  },
  selectprocessOverrule(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&stepCode=${paras.stepCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.selectprocessOverrule + ps);
  },
  rectificationAgree(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.rectificationAgree + ps);
  },
  rectificationOverrule(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&stepCode=${paras.stepCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.rectificationOverrule + ps);
  },
  abnormalAgree(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.abnormalAgree + ps);
  },
  abnormaOverrule(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&stepCode=${paras.stepCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.abnormaOverrule + ps);
  },
  collaAgree(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.collaAgree + ps);
  },
  teamAgree(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.teamAgree + ps);
  },
  crossChildAgree(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.crossChildAgree + ps);
  },
  crossChildOverrule(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.crossChildOverrule + ps);
  },
  selectApprovalfill(bizId, group) {
    return reqHelper.get({ year: 2018, bizId: bizId, group: group, }, apiUrl.common.selectApprovalfill);
  },
  collaOverrule(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&stepCode=${paras.stepCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.collaOverrule + ps);
  },
  teamBackToFirst(submit, paras) {
    let ps = `nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&stepCode=${paras.stepCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({ ...submit, }, apiUrl.internal.teamBackToFirst + ps);
  },
  getFlowPerson(docInsUuid,stepCode) {
    return reqHelper.postForm({ docInsUuid: docInsUuid,stepCode:stepCode, },apiUrl.internal.getFlowPerson );
  },
  /**
   * 获取文书详情
   * @param {*} param 
   * @param {*} cPath 
   * @returns 
   */
  getDoc(param, cPath) {
    return reqHelper.postForm(param, replaceDocCode(cPath, apiUrl.internal.getDoc));
  },
  /**
   * 保存文书
   * @param param
   * @param cPath cPath
   */
  saveDoc(param, cPath, urlParam) {
    return reqHelper.postJson(param, replaceDocCode(cPath, apiUrl.internal.saveDoc, urlParam));
  },
  /**
   * 提交文书
   * @param param
   * @param cPath cPath
   */
  submit(param, cPath, urlParam) {
    return reqHelper.postJson(param, replaceDocCode(cPath, apiUrl.internal.submitDoc, urlParam));
  },
  /**
   * 同意待办
   * @param param
   * @param cPath  cPath
   */
  agree(param, cPath, urlParam) {
    return reqHelper.postJson(param, replaceDocCode(cPath, apiUrl.internal.agree, urlParam));
  },
  /**
   * 驳回待办
   * @param param
   * @param cPath  cPath
   */
  backToFirst(param, cPath, urlParam) {
    return reqHelper.postJson(param, replaceDocCode(cPath, apiUrl.internal.backToFirst, urlParam));
  },
  /**
   * 返回上一步
   * @param param
   * @param cPath  cPath
   */
  disagree(param, cPath, urlParam) {
    return reqHelper.postJson(param, replaceDocCode(cPath, apiUrl.internal.disagree, urlParam));
  },
  /**
   * 获取审批历史记录
   * @param param
   * @returns {*}
   */
  flowHis(param) {
    return reqHelper.postForm(param, apiUrl.internal.flowHis);
  },
  /**
   * 获取审批人信息
   * @param param
   */
  flowNextPerson(param) {
    return reqHelper.postForm(param, apiUrl.internal.flowNextPerson);
  },
  /**
   * 获取文书配置
   * docUuid
   */
  getConfigById(param) {
    return reqHelper.postForm(param, apiUrl.internal.getConfigById);
  },
  getFlowNode(param) {
    return reqHelper.postForm(param, apiUrl.internal.getFlowNode);
  },

  /**
   * 获取抽象文书和配置
   * docInsUuid
   */
  getSdocById(param) {
    return reqHelper.postForm(param, apiUrl.internal.getSdocById);
  },
  /**
   * 获取查投结合文书
   */
  regularReportGetDoc(id,docUuid,bizUuid,) {
    return reqHelper.postForm(id,docUuid,bizUuid, apiUrl.internal.regularReportGetDoc);
  },
  /**
   * 查投结合文书提交
   */
  regularReportAgree(doc,paras){
    let ps = `?nextPersons=${paras.nextPersons}&gfaCode=${paras.gfaCode}&approveDate=${paras.approveDate}&approvePersonUuid=${paras.approvePersonUuid}&approveInfo=${paras.approveInfo}`;
    return reqHelper.postJson({...doc,}, apiUrl.internal.regularReportAgree + ps);
  },
  /**
   * 查投结合文书营销反馈
   */
  regularReportFeedback(regulist,) {
    return reqHelper.postForm(regulist, apiUrl.internal.regularReportFeedback);
  },
  /**
   * 查投结合反馈是否完成验证
   */
  regularReportCanVerify(regularReportUuid,) {
    return reqHelper.postForm({regularReportUuid:regularReportUuid,}, apiUrl.internal.regularReportCanVerify);
  },
  /**
   * 查投结合文书列表查询
   */
  regularReportList(params) {
    return reqHelper.postForm(params, apiUrl.internal.regularReportList);
  },
};
/**
 * 替换一下docUrl
 * @param docCode
 * @param url
 * @returns {*}
 */
function replaceDocCode(docCode, url, urlParam) {
  url = url.replace('{x}', docCode);
  if (!urlParam) {
    return url;
  }
  let p = url.indexOf("?") > -1;
  // url 无参数去掉？号 2024-7-10 fsx 开始
  let keys = Object.keys(urlParam);
  if (!p && keys.length > 0) {
    url = url + '?';
  }
  // url 无参数去掉？号 2024-7-10 fsx 结束
  for (let name in urlParam) {
    url = url + name + '=' + urlParam[name] + '&';
  }
  // 去掉最后一个& 2024-7-10 fsx 开始
  let endStr = url.substr(url.length - 1, 1);
  if (endStr === '&') {
    url = url.substr(0, url.length - 1);
  }
  // 去掉最后一个& 2024-7-10 fsx 结束
  return url;
}